﻿using System;
using System.IO;
using System.Runtime.Serialization;

namespace SBPweb.PROvibe.Server.Framework.Actors.Communication
{

    [Serializable]
    [DataContract]
    public class MessageBody
    {

        public MessageBody()
        {
        }

        public MessageBody(MessageContentBase content)
            : this(((content != null) ? content.GetType() : typeof(object)).FullName, content)
        {
        }

        public MessageBody(string type, MessageContentBase content)
        {
            this.Type = type;
            this.Content = content;
        }

        [DataMember]
        public virtual string Type
        {
            get;
            set;
        }

        [DataMember]
        public virtual MessageContentBase Content
        {
            get;
            set;
        }

        //public static XmlObjectSerializer GetSerializer()
        //{
        //    return new DataContractSerializer(typeof(MessageBody), new Type[] { typeof(KeepAliveContent) });
        //}

    }

    [Serializable]
    [DataContract]
    public class MessageBody<T> : MessageBody
        where T : MessageContentBase
    {

        public MessageBody()
            : base()
        {
        }

        public MessageBody(T value)
            : base(value)
        {
        }

        public MessageBody(string type, T value)
            : base(type, value)
        {
        }

        public MessageBody(MessageBody ancestor)
        {
            this.Type = ancestor.Type;
            this.Content = (T)ancestor.Content;
        }

        [DataMember]
        public virtual new T Content
        {
            get
            {
                return (T)base.Content;
            }
            set
            {
                base.Content = value;
            }
        }

    }

}